/*
 * Copyright (c) 2020 - ~, HIT_HERO Team
 *
 * X-SPIDER APP SOUCE FILE
 * Used in RT-Thread Operate System
 *
 * Change Logs:
 * Date           Author       Notes                Mail
 * 2020-12-16     WangXi       first version        WangXi_chn@foxmail.com
 */
 
#include <stdio.h>
#include "App_XSpider.h"

static void APP_XSpiderInit(APP_XSPIDER *Application);
static void APP_XSpiderRun(APP_XSPIDER *Application);
static void APP_XSpiderEyesChange(APP_XSPIDER *Application,enum COLOR_LED color);
static void APP_XSpiderJointPlace(APP_XSPIDER *Application,rt_uint16_t *angle);

static void XSpiderLed_entry(void *parameter);
static void XSpiderOrderUpdate_entry(void *parameter);
static void XSpiderControl_entry(void *parameter);
static void XSpiderAction_entry(void *parameter);
//--------------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------------

void APP_XSpider_Config(APP_XSPIDER *Application)
{
	if(	Application->Method_Init	==	NULL &&
		Application->Method_Run		==	NULL &&
		Application->Method_EyeChange	==	NULL &&
		Application->Method_JointPlace	==	NULL

    ){  
        /* Link the Method */
        Application->Method_Init = APP_XSpiderInit;
		Application->Method_Run	 = APP_XSpiderRun;
		Application->Method_EyeChange = APP_XSpiderEyesChange;
		Application->Method_JointPlace = APP_XSpiderJointPlace;
		
    }
    else{
        rt_kprintf("Warning: APP_XSpider is Configed twice\n");
        return;
    }

    /* Device Init */
    Application->Method_Init(Application);
	
	/* Module Config */
	Module_Led_Config(&(Application->dev_Led));
	Module_Led_Config(&(Application->dev_Led_RedEye));
	Module_Led_Config(&(Application->dev_Led_GreenEye));
	Module_Led_Config(&(Application->dev_Led_BlueEye));
	Module_Oled_Config(&(Application->dev_Oled));
	Module_BlueToothHC06_Config(&(Application->dev_Controler));
	
	for(int i = 0;i<ID_STEERING_END;i++)
		Module_Steering_Config(&(Application->dev_Steering[i]));
	

    return;
}

static void APP_XSpiderInit(APP_XSPIDER *Application)
{
	/* Module param list ------------------------------------------------------------------------- */
	/* LED Pin device */
	/* Out: PC13 */
	Application->dev_Led.Property_pin = GET_PIN(C, 13);
	Application->dev_Led.Property_Mode = FLASH_LED_MODE;
	Application->dev_Led.LED_TIME_CYCLE = 1500;
	Application->dev_Led.LED_TIME_OUTPUT = 150;
	
	/* Out: PA0 */
	Application->dev_Led_RedEye.Property_pin = GET_PIN(A, 0);
	Application->dev_Led_RedEye.Property_Mode = SIMPLE_LED_MODE;
	
	/* Out: PC14 */
	Application->dev_Led_GreenEye.Property_pin = GET_PIN(C, 14);
	Application->dev_Led_GreenEye.Property_Mode = SIMPLE_LED_MODE;
	
	/* Out: PC15 */
	Application->dev_Led_BlueEye.Property_pin = GET_PIN(C, 15);
	Application->dev_Led_BlueEye.Property_Mode = SIMPLE_LED_MODE;
	
	/* Blue Tooth UART Pin device */
	/* TX: PA2 */
	/* RX: PA3 */
	/* In: PA4 */
	Application->dev_Controler.Property_UartDevName = "uart2";
	Application->dev_Controler.ConnectStatusPin = GET_PIN(A, 4);
	Application->dev_Controler.ConnectCheckSwitch = 0;
	
	/* OLED communication device */
	/* Pin:	PA6 OLED SCK */
	/* Pin:	PA5 OLED SDA */
	Application->dev_Oled.Property_SCKpin = GET_PIN(B, 14);
	Application->dev_Oled.Property_SDApin = GET_PIN(B, 15);
	Application->dev_Oled.Property_Y_WIDTH = 32;
	Application->dev_Oled.Property_X_WIDTH = 128;
	
	/* Steering Engine Pwm device */
	{
	/* PWM PA15 */
	Application->dev_Steering[L1_D1].Property_SteerType = SG90;
	Application->dev_Steering[L1_D1].Property_PwmDevName = "pwm2";
	Application->dev_Steering[L1_D1].Property_PWM_CHANNEL = 1;
	Application->dev_Steering[L1_D1].Property_PulseMINus = 500;
	Application->dev_Steering[L1_D1].Property_PulseMAXus = 2200;
	Application->dev_Steering[L1_D1].Property_AngleMAX = 180;
	Application->dev_Steering[L1_D1].Property_InitAngle = 115;
	
	/* PWM PB3 */
	Application->dev_Steering[L1_D2].Property_SteerType = SG90;
	Application->dev_Steering[L1_D2].Property_PwmDevName = "pwm2";
	Application->dev_Steering[L1_D2].Property_PWM_CHANNEL = 2;
	Application->dev_Steering[L1_D2].Property_PulseMINus = 500;
	Application->dev_Steering[L1_D2].Property_PulseMAXus = 2500;
	Application->dev_Steering[L1_D2].Property_AngleMAX = 180;
	Application->dev_Steering[L1_D2].Property_InitAngle = 90;

	/* PWM PB10 */
	Application->dev_Steering[L1_D3].Property_SteerType = SG90;
	Application->dev_Steering[L1_D3].Property_PwmDevName = "pwm2";
	Application->dev_Steering[L1_D3].Property_PWM_CHANNEL = 3;
	Application->dev_Steering[L1_D3].Property_PulseMINus = 500;
	Application->dev_Steering[L1_D3].Property_PulseMAXus = 2200;
	Application->dev_Steering[L1_D3].Property_AngleMAX = 180;
	Application->dev_Steering[L1_D3].Property_InitAngle = 90;
	
	/* PWM PA6 */
	Application->dev_Steering[L2_D1].Property_SteerType = SG90;
	Application->dev_Steering[L2_D1].Property_PwmDevName = "pwm3";
	Application->dev_Steering[L2_D1].Property_PWM_CHANNEL = 1;
	Application->dev_Steering[L2_D1].Property_PulseMINus = 500;
	Application->dev_Steering[L2_D1].Property_PulseMAXus = 2300;
	Application->dev_Steering[L2_D1].Property_AngleMAX = 180;
	Application->dev_Steering[L2_D1].Property_InitAngle = 65;
	
	/* PWM PA7 */
	Application->dev_Steering[L2_D2].Property_SteerType = SG90;
	Application->dev_Steering[L2_D2].Property_PwmDevName = "pwm3";
	Application->dev_Steering[L2_D2].Property_PWM_CHANNEL = 2;
	Application->dev_Steering[L2_D2].Property_PulseMINus = 500;
	Application->dev_Steering[L2_D2].Property_PulseMAXus = 2400;
	Application->dev_Steering[L2_D2].Property_AngleMAX = 180;
	Application->dev_Steering[L2_D2].Property_InitAngle = 90;
	
	/* PWM PB0 */
	Application->dev_Steering[L2_D3].Property_SteerType = SG90;
	Application->dev_Steering[L2_D3].Property_PwmDevName = "pwm3";
	Application->dev_Steering[L2_D3].Property_PWM_CHANNEL = 3;
	Application->dev_Steering[L2_D3].Property_PulseMINus = 500;
	Application->dev_Steering[L2_D3].Property_PulseMAXus = 2300;
	Application->dev_Steering[L2_D3].Property_AngleMAX = 180;
	Application->dev_Steering[L2_D3].Property_InitAngle = 90;
	
	/* PWM PB6 */
	Application->dev_Steering[L3_D1].Property_SteerType = SG90;
	Application->dev_Steering[L3_D1].Property_PwmDevName = "pwm4";
	Application->dev_Steering[L3_D1].Property_PWM_CHANNEL = 1;
	Application->dev_Steering[L3_D1].Property_PulseMINus = 550;
	Application->dev_Steering[L3_D1].Property_PulseMAXus = 2550;
	Application->dev_Steering[L3_D1].Property_AngleMAX = 180;
	Application->dev_Steering[L3_D1].Property_InitAngle = 115;
	
	/* PWM PB7 */
	Application->dev_Steering[L3_D2].Property_SteerType = SG90;
	Application->dev_Steering[L3_D2].Property_PwmDevName = "pwm4";
	Application->dev_Steering[L3_D2].Property_PWM_CHANNEL = 2;
	Application->dev_Steering[L3_D2].Property_PulseMINus = 500;
	Application->dev_Steering[L3_D2].Property_PulseMAXus = 2500;
	Application->dev_Steering[L3_D2].Property_AngleMAX = 180;
	Application->dev_Steering[L3_D2].Property_InitAngle = 90;
	
	/* PWM PB8 */
	Application->dev_Steering[L3_D3].Property_SteerType = SG90;
	Application->dev_Steering[L3_D3].Property_PwmDevName = "pwm4";
	Application->dev_Steering[L3_D3].Property_PWM_CHANNEL = 3;
	Application->dev_Steering[L3_D3].Property_PulseMINus = 500;
	Application->dev_Steering[L3_D3].Property_PulseMAXus = 2300;
	Application->dev_Steering[L3_D3].Property_AngleMAX = 180;
	Application->dev_Steering[L3_D3].Property_InitAngle = 90;
	
	/* PWM PB11 */
	Application->dev_Steering[L4_D1].Property_SteerType = SG90;
	Application->dev_Steering[L4_D1].Property_PwmDevName = "pwm2";
	Application->dev_Steering[L4_D1].Property_PWM_CHANNEL = 4;
	Application->dev_Steering[L4_D1].Property_PulseMINus = 500;
	Application->dev_Steering[L4_D1].Property_PulseMAXus = 2300;
	Application->dev_Steering[L4_D1].Property_AngleMAX = 180;
	Application->dev_Steering[L4_D1].Property_InitAngle = 65;
	
	/* PWM PB1 */
	Application->dev_Steering[L4_D2].Property_SteerType = SG90;
	Application->dev_Steering[L4_D2].Property_PwmDevName = "pwm3";
	Application->dev_Steering[L4_D2].Property_PWM_CHANNEL = 4;
	Application->dev_Steering[L4_D2].Property_PulseMINus = 600;
	Application->dev_Steering[L4_D2].Property_PulseMAXus = 2600;
	Application->dev_Steering[L4_D2].Property_AngleMAX = 180;
	Application->dev_Steering[L4_D2].Property_InitAngle = 90;
	
	/* PWM PB9 */
	Application->dev_Steering[L4_D3].Property_SteerType = SG90;
	Application->dev_Steering[L4_D3].Property_PwmDevName = "pwm4";
	Application->dev_Steering[L4_D3].Property_PWM_CHANNEL = 4;
	Application->dev_Steering[L4_D3].Property_PulseMINus = 500;
	Application->dev_Steering[L4_D3].Property_PulseMAXus = 2200;
	Application->dev_Steering[L4_D3].Property_AngleMAX = 180;
	Application->dev_Steering[L4_D3].Property_InitAngle = 90;
	
	}
	
	/* Data Sheet Default Value ------------------------------------------------------------------ */
	
	
}

static void APP_XSpiderRun(APP_XSPIDER *Application)
{

	Application->dev_Led.Method_Set(&(Application->dev_Led),4);
	
	Application->dev_Steering[L1_D1].Method_Enable(&(Application->dev_Steering[L1_D1]));
	Application->dev_Steering[L1_D2].Method_Enable(&(Application->dev_Steering[L1_D2]));
	Application->dev_Steering[L1_D3].Method_Enable(&(Application->dev_Steering[L1_D3]));
	Application->dev_Steering[L2_D1].Method_Enable(&(Application->dev_Steering[L2_D1]));
	Application->dev_Steering[L2_D2].Method_Enable(&(Application->dev_Steering[L2_D2]));
	Application->dev_Steering[L2_D3].Method_Enable(&(Application->dev_Steering[L2_D3]));
	Application->dev_Steering[L3_D1].Method_Enable(&(Application->dev_Steering[L3_D1]));
	Application->dev_Steering[L3_D2].Method_Enable(&(Application->dev_Steering[L3_D2]));
	Application->dev_Steering[L3_D3].Method_Enable(&(Application->dev_Steering[L3_D3]));
	Application->dev_Steering[L4_D1].Method_Enable(&(Application->dev_Steering[L4_D1]));
	Application->dev_Steering[L4_D2].Method_Enable(&(Application->dev_Steering[L4_D2]));
	Application->dev_Steering[L4_D3].Method_Enable(&(Application->dev_Steering[L4_D3]));
	
	rt_thread_mdelay(500);
	
	Application->Method_EyeChange(Application,BLUE);
	Application->value_action = STAND;
	Application->value_lastaction = ACTION_END;
	
	char ch[20];
	sprintf(ch,"Hello,Xspider!");
	Application->dev_Oled.Method_ShowStr(&(Application->dev_Oled),0,0,ch,2);
	
	rt_thread_t XSpiderLed_thread = rt_thread_create("XSPD-Led", XSpiderLed_entry, 
									Application,512, RT_THREAD_PRIORITY_MAX - 6, 30);
    if (XSpiderLed_thread != RT_NULL){
        rt_thread_startup(XSpiderLed_thread);
    }
	
	rt_thread_t XSpiderOrderUpdate_thread = rt_thread_create("XSPD-OrderUp", XSpiderOrderUpdate_entry, 
									Application,512, RT_THREAD_PRIORITY_MAX - 5, 30);
    if (XSpiderOrderUpdate_thread != RT_NULL){
        rt_thread_startup(XSpiderOrderUpdate_thread);
    }
	
	rt_thread_t XSpiderControl_thread = rt_thread_create("XSPD-Control", XSpiderControl_entry, 
									Application,512, RT_THREAD_PRIORITY_MAX - 4, 30);
    if (XSpiderControl_thread != RT_NULL){
        rt_thread_startup(XSpiderControl_thread);
    }
	
	rt_thread_t XSpiderAction_thread = rt_thread_create("XSPD-Action", XSpiderAction_entry, 
									Application,512, RT_THREAD_PRIORITY_MAX - 3, 30);
    if (XSpiderAction_thread != RT_NULL){
        rt_thread_startup(XSpiderAction_thread);
    }
	
}

/* thread entry list ----------------------------------------------------------------------------- */
static void XSpiderLed_entry(void *parameter)
{
	APP_XSPIDER *Application = (APP_XSPIDER *)parameter;
	
	while(1)
	{
		rt_thread_mdelay(1);
		Application->dev_Led.Method_Handle(&(Application->dev_Led));
	}	
}

static void XSpiderOrderUpdate_entry(void *parameter)
{
	APP_XSPIDER *Application = (APP_XSPIDER *)parameter;
	
	rt_thread_mdelay(1);
	Application->dev_Controler.Method_Feed(&(Application->dev_Controler));
	
}

static void XSpiderControl_entry(void *parameter)
{
	APP_XSPIDER *Application = (APP_XSPIDER *)parameter;
	while(1)
	{
		rt_thread_mdelay(1);
		
		switch(Application->dev_Controler.Value_keyMask)
		{
			case (0x0001<<0)://key1  	
				Application->Method_EyeChange(Application,NONE);
				Application->value_delaytic = 0;
				Application->value_action = REST;
				break;
			case (0x0001<<1)://key2 
				Application->Method_EyeChange(Application,GREEN);
				Application->value_delaytic = 0;
				Application->value_action = GO_AHEAD;
				break;
			case (0x0001<<2)://key3 	
				Application->Method_EyeChange(Application,RED);
				Application->value_delaytic = 0;
				Application->value_action = DEBUG;
				break;
			case (0x0001<<3)://key4 	
				Application->Method_EyeChange(Application,GREEN);
				Application->value_delaytic = 0;
				Application->value_action = GO_LEFT;
				break;
			case (0x0001<<4)://key5 	
				Application->Method_EyeChange(Application,BLUE);
				Application->value_delaytic = 0;
				Application->value_action = STAND;
				break;
			case (0x0001<<5)://key6 	
				Application->Method_EyeChange(Application,GREEN);
				Application->value_delaytic = 0;
				Application->value_action = GO_RIGHT;
				break;
			case (0x0001<<6)://key7 
				Application->Method_EyeChange(Application,GREEN);
				Application->value_delaytic = 0;
				Application->value_action = RAISEHAND;
				break;
			case (0x0001<<7)://key8 
				Application->Method_EyeChange(Application,BLUE);
				Application->value_delaytic = 0;
				Application->value_action = GO_BACK;
				break;
			case (0x0001<<8)://key9 
				
				break;
			case (0x0001<<9)://key10 
				Application->Method_EyeChange(Application,GREEN);
				Application->value_delaytic = 0;
				Application->value_action = TURE_LEFT;
				break;
			case (0x0001<<10)://key11 
			
				break;
			case (0x0001<<11)://key12 
				Application->Method_EyeChange(Application,GREEN);
				Application->value_delaytic = 0;
				Application->value_action = TURE_RIGHT;
				break;			
		}
		Application->dev_Controler.Value_keyMask = 0;
	}
}

#define period_tic 200/2

static void XSpiderAction_entry(void *parameter)
{
	APP_XSPIDER *Application = (APP_XSPIDER *)parameter;
	while(1)
	{
		rt_thread_mdelay(1);
		
		switch(Application->value_action)
		{
			case REST:{
				if(Application->value_lastaction != Application->value_action)
				{
					rt_uint16_t angle[12] = {180,90,60,		0,90,135,		170,90,40,		20,90,120};
					Application->Method_JointPlace(Application,angle);
					Application->value_lastaction = Application->value_action;
				}
				break;
			}
			case DEBUG:{
				if(Application->value_lastaction != Application->value_action)
				{
					rt_uint16_t angle[12] = {90,90,90,		90,90,90,		90,90,90,		90,90,90};
					Application->Method_JointPlace(Application,angle);
					Application->value_lastaction = Application->value_action;
				}
				break;
			}
			case STAND:{
				if(Application->value_lastaction != Application->value_action)
				{
					rt_uint16_t angle[12] = {115,60,70,		65,120,120,		115,60,50,		65,120,100};
					Application->Method_JointPlace(Application,angle);
					Application->value_lastaction = Application->value_action;
				}
				break;
			}
			case GO_AHEAD:{
				
				Application->value_delaytic++;
				
				if(Application->value_delaytic == period_tic){
					rt_uint16_t angle[12] = {135,50,60,		65,120,120,		95,50,40,		65,120,100};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 3*period_tic){
					rt_uint16_t angle[12] = {135,70,80,		85,130,130,		95,70,60,		45,130,110};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 5*period_tic){
					rt_uint16_t angle[12] = {95,70,80,		85,110,110,		135,70,60,		45,110,90};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 7*period_tic){
					rt_uint16_t angle[12] = {115,60,70,		45,110,110,		115,60,50,		85,110,90};
					Application->Method_JointPlace(Application,angle);
				}
				
				
				Application->value_lastaction = Application->value_action;
				
				if(Application->value_delaytic >= 8*period_tic)
					Application->value_delaytic = 0;
				break;
			}
			case GO_BACK:{
				
				Application->value_delaytic++;
				
				if(Application->value_delaytic == period_tic){
					rt_uint16_t angle[12] = {95,50,60,		65,120,120,		135,50,40,		65,120,100};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 3*period_tic){
					rt_uint16_t angle[12] = {95,70,80,		45,130,130,		135,70,60,		85,130,110};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 5*period_tic){
					rt_uint16_t angle[12] = {135,70,80,		45,110,110,		95,70,60,		85,110,90};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 7*period_tic){
					rt_uint16_t angle[12] = {115,60,70,		85,110,110,		115,60,50,		45,110,90};
					Application->Method_JointPlace(Application,angle);
				}
				
				
				Application->value_lastaction = Application->value_action;
				
				if(Application->value_delaytic >= 8*period_tic)
					Application->value_delaytic = 0;
				break;
			}
			case TURE_LEFT:{
				
				Application->value_delaytic++;
				
				if(Application->value_delaytic == period_tic){
					rt_uint16_t angle[12] = {135,50,60,		65,120,120,		135,50,40,		65,120,100};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 3*period_tic){
					rt_uint16_t angle[12] = {135,70,80,		85,130,130,		135,70,60,		85,130,110};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 5*period_tic){
					rt_uint16_t angle[12] = {95,70,80,		85,110,110,		95,70,60,		85,110,90};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 7*period_tic){
					rt_uint16_t angle[12] = {115,60,70,		45,110,110,		115,60,50,		45,110,90};
					Application->Method_JointPlace(Application,angle);
				}
				
				
				Application->value_lastaction = Application->value_action;
				
				if(Application->value_delaytic >= 8*period_tic)
					Application->value_delaytic = 0;
				break;
			}
			case TURE_RIGHT:{
				
				Application->value_delaytic++;
				
				if(Application->value_delaytic == period_tic){
					rt_uint16_t angle[12] = {95,50,60,		65,120,120,		95,50,40,		65,120,100};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 3*period_tic){
					rt_uint16_t angle[12] = {95,70,80,		45,130,130,	95,70,60,		45,130,110};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 5*period_tic){
					rt_uint16_t angle[12] = {135,70,80,		45,110,110,	135,70,60,		45,110,90};
					Application->Method_JointPlace(Application,angle);
				}else if(Application->value_delaytic == 7*period_tic){
					rt_uint16_t angle[12] = {115,60,70,		85,110,110,		115,60,50,		85,110,90};
					Application->Method_JointPlace(Application,angle);
				}
				
				
				Application->value_lastaction = Application->value_action;
				
				if(Application->value_delaytic >= 8*period_tic)
					Application->value_delaytic = 0;
				break;
			}
			case GO_LEFT:{
				
				Application->value_delaytic++;
				
//				if(delay_tic == period_tic){
//					rt_uint16_t angle[12] = {95,50,60,		65,120,120,		95,50,40,		65,120,100};
//					Application->Method_JointPlace(Application,angle);
//				}else if(delay_tic == 3*period_tic){
//					rt_uint16_t angle[12] = {95,70,80,		45,130,130,	95,70,60,		45,130,110};
//					Application->Method_JointPlace(Application,angle);
//				}else if(delay_tic == 5*period_tic){
//					rt_uint16_t angle[12] = {135,70,80,		45,110,110,	135,70,60,		45,110,90};
//					Application->Method_JointPlace(Application,angle);
//				}else if(delay_tic == 7*period_tic){
//					rt_uint16_t angle[12] = {115,60,70,		85,110,110,		115,60,50,		85,110,90};
//					Application->Method_JointPlace(Application,angle);
//				}
							
				Application->value_lastaction = Application->value_action;
				
				if(Application->value_delaytic >= 8*period_tic)
					Application->value_delaytic = 0;
				break;
			}
			case GO_RIGHT:{
				
				Application->value_delaytic++;
				
//				if(delay_tic == period_tic){
//					rt_uint16_t angle[12] = {95,50,60,		65,120,120,		95,50,40,		65,120,100};
//					Application->Method_JointPlace(Application,angle);
//				}else if(delay_tic == 3*period_tic){
//					rt_uint16_t angle[12] = {95,70,80,		45,130,130,		95,70,60,		45,130,110};
//					Application->Method_JointPlace(Application,angle);
//				}else if(delay_tic == 5*period_tic){
//					rt_uint16_t angle[12] = {135,70,80,		45,110,110,		135,70,60,		45,110,90};
//					Application->Method_JointPlace(Application,angle);
//				}else if(delay_tic == 7*period_tic){
//					rt_uint16_t angle[12] = {115,60,70,		85,110,110,		115,60,50,		85,110,90};
//					Application->Method_JointPlace(Application,angle);
//				}
				
				
				Application->value_lastaction = Application->value_action;
				
				if(Application->value_delaytic >= 8*period_tic)
					Application->value_delaytic = 0;
				break;
			}
			case RAISEHAND:{
				
				Application->value_delaytic++;
				//115,60,70,		65,120,120,		115,60,50,		65,120,100
				if(Application->value_lastaction != Application->value_action)
				{
					if(Application->value_delaytic == 3*period_tic){
						rt_uint16_t angle[12] = {115,60,70,		75,130,130,		115,60,50,		65,120,100};
						Application->Method_JointPlace(Application,angle);
					}else if(Application->value_delaytic == 6*period_tic){
						rt_uint16_t angle[12] = {115,60,70,		75,120,120,		115,60,50,		65,120,100};
						Application->Method_JointPlace(Application,angle);
					}else if(Application->value_delaytic == 9*period_tic){
						rt_uint16_t angle[12] = {115,60,70,		75,120,120,		115,60,50,		25,130,110};
						Application->Method_JointPlace(Application,angle);
					}else if(Application->value_delaytic == 12*period_tic){
						rt_uint16_t angle[12] = {115,60,70,		75,120,120,		115,60,50,		25,120,100};
						Application->Method_JointPlace(Application,angle);
					}else if(Application->value_delaytic == 15*period_tic){
						rt_uint16_t angle[12] = {115,0,70,		75,120,120,		115,60,50,		25,120,100};
						Application->Method_JointPlace(Application,angle);
					}else if(Application->value_delaytic == 18*period_tic){
						rt_uint16_t angle[12] = {115,0,100,		75,120,120,		115,60,50,		25,120,100};
						Application->Method_JointPlace(Application,angle);
					}else if(Application->value_delaytic == 21*period_tic){
						rt_uint16_t angle[12] = {115,0,70,		75,120,120,		115,60,50,		25,120,100};
						Application->Method_JointPlace(Application,angle);
					}else if(Application->value_delaytic == 24*period_tic){
						rt_uint16_t angle[12] = {115,0,100,		75,120,120,		115,60,50,		25,120,100};
						Application->Method_JointPlace(Application,angle);
					}else if(Application->value_delaytic == 27*period_tic){
						rt_uint16_t angle[12] = {115,0,70,		75,120,120,		115,60,50,		25,120,100};
						Application->Method_JointPlace(Application,angle);
						Application->value_lastaction = Application->value_action;
					}
				
				}
				
				if(Application->value_delaytic >= 30*period_tic)
					Application->value_delaytic = 0;
				break;
			}
			case ACTION_END:{
			
				break;
			}	
		}
		
	}
}

void APP_XSpiderEyesChange(APP_XSPIDER *Application,enum COLOR_LED color)
{
	switch(color)
	{
		case NONE:
			Application->dev_Led_BlueEye.Method_Set(&(Application->dev_Led_BlueEye),MODULE_LED_OFF);
			Application->dev_Led_RedEye.Method_Set(&(Application->dev_Led_RedEye),MODULE_LED_OFF);
			Application->dev_Led_GreenEye.Method_Set(&(Application->dev_Led_GreenEye),MODULE_LED_OFF);
			break;
		case RED:
			Application->dev_Led_BlueEye.Method_Set(&(Application->dev_Led_BlueEye),MODULE_LED_OFF);
			Application->dev_Led_RedEye.Method_Set(&(Application->dev_Led_RedEye),MODULE_LED_ON);
			Application->dev_Led_GreenEye.Method_Set(&(Application->dev_Led_GreenEye),MODULE_LED_OFF);
			break;
		case GREEN:
			Application->dev_Led_BlueEye.Method_Set(&(Application->dev_Led_BlueEye),MODULE_LED_OFF);
			Application->dev_Led_RedEye.Method_Set(&(Application->dev_Led_RedEye),MODULE_LED_OFF);
			Application->dev_Led_GreenEye.Method_Set(&(Application->dev_Led_GreenEye),MODULE_LED_ON);
			break;
		case BLUE:
			Application->dev_Led_BlueEye.Method_Set(&(Application->dev_Led_BlueEye),MODULE_LED_ON);
			Application->dev_Led_RedEye.Method_Set(&(Application->dev_Led_RedEye),MODULE_LED_OFF);
			Application->dev_Led_GreenEye.Method_Set(&(Application->dev_Led_GreenEye),MODULE_LED_OFF);
			break;
		case COLOR_LED_END:
			break;
	}
}

void APP_XSpiderJointPlace(APP_XSPIDER *Application,rt_uint16_t *angle)
{
	Application->dev_Steering[L1_D1].Method_SetAngle(&(Application->dev_Steering[L1_D1]),angle[0]);
	Application->dev_Steering[L1_D2].Method_SetAngle(&(Application->dev_Steering[L1_D2]),angle[1]);
	Application->dev_Steering[L1_D3].Method_SetAngle(&(Application->dev_Steering[L1_D3]),angle[2]);
	Application->dev_Steering[L2_D1].Method_SetAngle(&(Application->dev_Steering[L2_D1]),angle[3]);
	Application->dev_Steering[L2_D2].Method_SetAngle(&(Application->dev_Steering[L2_D2]),angle[4]);
	Application->dev_Steering[L2_D3].Method_SetAngle(&(Application->dev_Steering[L2_D3]),angle[5]);
	Application->dev_Steering[L3_D1].Method_SetAngle(&(Application->dev_Steering[L3_D1]),angle[6]);
	Application->dev_Steering[L3_D2].Method_SetAngle(&(Application->dev_Steering[L3_D2]),angle[7]);
	Application->dev_Steering[L3_D3].Method_SetAngle(&(Application->dev_Steering[L3_D3]),angle[8]);
	Application->dev_Steering[L4_D1].Method_SetAngle(&(Application->dev_Steering[L4_D1]),angle[9]);
	Application->dev_Steering[L4_D2].Method_SetAngle(&(Application->dev_Steering[L4_D2]),angle[10]);
	Application->dev_Steering[L4_D3].Method_SetAngle(&(Application->dev_Steering[L4_D3]),angle[11]);
}

/************************ (C) COPYRIGHT 2020 WANGXI **************END OF FILE****/
